<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'north'" class="center">
        <div class="webmap">
            <p class="webmaptip">当前位置:</p>
            <a href="javascript:;" class="easyui-link" data-options="plain:true">财务管理</a>
            <p class="webmaptip">></p>
            <a href="javascript:;" class="easyui-link" data-options="plain:true">用户资金统计</a>
        </div>
        <div class="querybycon">
            <form id="query">
                <div class="queryinfo">
                    <div>用户名<input type="text" name="telephone"></div>
                    <div class="query">
                        <a id="querybtn" href="javascript:;" class="easyui-linkbutton  "
                           data-options="iconCls:'fa fa-search'"></a>
                    </div>
                </div>
            </form>
        </div>
        <div class="querybtn">
            <a id="exportbtn" href="javascript:;" class="easyui-linkbutton  "
               data-options="iconCls:'fa fa-search'">导出</a>
        </div>
        <div class="separator"></div>
    </div>
    <div data-options="region:'center'" class="center">
        <table id="list"></table>
    </div>
</div>
<script type="text/javascript">
    var listUrl = "/user/fundStatistics";
    var exportUrl = "/user/export";
    var columns = [[{
        field: 'id',
        checkbox: true
    }, {
        field: 'telephone',
        title: '用户名',
    }, {
        field: 'name',
        title: '姓名',
    }
        , {
            field: 'sum',
            title: '资产总额(元)',
            formatter: function (value, row, index) {
                console.info(row.amountStatistics);
                if (row != null && row.amountStatistics != null) {
                    return formatNumber(row.amountStatistics.sum, 2);
                } else {
                    return 0.00;
                }
            }
        }, {
            field: 'availableBalance',
            title: '可用余额(元)',
            formatter: function (value, row, index) {
                if (row != null && row.amountStatistics != null) {
                    return formatNumber(row.amountStatistics.availableBalance, 2);
                } else {
                    return 0.00;
                }
            }
        }, {
            field: 'freezingAmount',
            title: '冻结金额(元)',
            formatter: function (value, row, index) {
                if (row != null && row.amountStatistics != null) {
                    return formatNumber(row.amountStatistics.freezingAmount, 2);
                } else {
                    return 0.00;
                }
            }
        }, {
            field: 'investSum',
            title: '总投资额(元)',
            formatter: function (value, row, index) {
                if (row != null && row.amountStatistics != null) {
                    return formatNumber(row.amountStatistics.investSum, 2);
                } else {
                    return 0.00;
                }
            }
        }, {
            field: 'accumulatedIncome',
            title: '累计收益(元)',
            formatter: function (value, row, index) {
                if (row != null && row.amountStatistics != null) {
                    return formatNumber(row.amountStatistics.accumulatedIncome, 2);
                } else {
                    return 0.00;
                }
            }
        }, {
            field: 'dueReceiveSum',
            title: '待收总额(元)',
            formatter: function (value, row, index) {
                if (row != null && row.amountStatistics != null) {
                    return formatNumber(row.amountStatistics.unReceiveCapital + row.amountStatistics.unReceiveInterest, 2);
                } else {
                    return 0.00;
                }
            }
        }, {
            field: 'loanSum',
            title: '借款总额(元)',
            formatter: function (value, row, index) {
                if (row != null && row.amountStatistics != null) {
                    return formatNumber(row.amountStatistics.loanSum, 2);
                } else {
                    return 0.00;
                }
            }
        }, {
            field: 'dueRepaymentSum',
            title: '待还总额(元)',
            formatter: function (value, row, index) {
                if (row != null && row.amountStatistics != null) {
                    return formatNumber(row.amountStatistics.dueRepayCapital + row.amountStatistics.dueRepayInterest, 2);
                } else {
                    return 0.00;
                }
            }
        }, {
            field: 'rechargeSum',
            title: '总充值金额(元)',
            formatter: function (value, row, index) {
                if (row != null && row.amountStatistics != null) {
                    return formatNumber(row.amountStatistics.rechargeSum, 2);
                } else {
                    return 0.00;
                }
            }
        }, {
            field: 'withdrawSum',
            title: '总提现金额(元)',
            formatter: function (value, row, index) {
                if (row != null && row.amountStatistics != null) {
                    return formatNumber(row.amountStatistics.withdrawSum, 2);
                } else {
                    return 0.00;
                }
            }
        }
    ]];
    list.init({url: listUrl, columns: columns});
    $("#exportbtn").click(function () {
        var obj = $("#query").serializeObject();
        window.open(exportUrl + "?" + $(obj).formatJson2Url());
    });
    function formatNumber(value, fixed) {
        var number = Number(value);
        if (isNaN(number)) {
            return '';
        } else {
            return number.toFixed(2);
        }
    }
</script>
